/*
 * MemAudio.h
 *
 *  Created on: 15 Sep, 2017
 *      Author: buffon
 */

#ifndef MEMAUDIO_H_
#define MEMAUDIO_H_
#include<iostream>
#include <string.h>
using namespace std;

#include "base/ThreadPool.h"
#include "TimerTask.h"

#define MAX_SUPPORT_SIZE 50*1024*1024
#define MAX_STD_SIZE 40*1024*1024
#define SWITCH_SIZE 45*1024*1024
#define TIME_DEALING 30
#define TIME_INTERVAL 5
#define ARRAY_LEN (TIME_DEALING/TIME_INTERVAL)

//typedef struct{
//	int nBegin;
//	int nEnd;
//	bool bReady;
//}MemAudioSlice;

class MemAudio{

public:
	MemAudio();
	virtual ~MemAudio();
public:
	char* getBuffer(){
		return pCurBuffer;
	}
	int getBufferLen(){
		return lenBytes;
	}

	int appendBuffer(char* pData,int length,bool flag);

//	bool saveToFile(char* pData,int length);
private:
	int buffNum;
	char *pSaveBuffer,*pNewBuffer,*pCurBuffer,*pNextBuffer;
	int lenBytes,lenBytesCp;
	bool bSaveIsMaster;

	int nLenArray[ARRAY_LEN];
	int curLen;
	int nIndex;
	struct timeval prevTime;
	bool bReady;
	CWorkerThread* worker;
};



#endif /* MEMAUDIO_H_ */
